package com.hxy.travel.service.impl;

import com.alibaba.dubbo.config.annotation.Service;
import com.alibaba.fastjson.JSON;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.hxy.travel.dao.TravelItemDao;
import com.hxy.travel.entity.PageResult;
import com.hxy.travel.entity.QueryPageBean;
import com.hxy.travel.pojo.TravelItem;
import com.hxy.travel.service.TravelItemService;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

@Service(interfaceClass = TravelItemService.class)
public class TravelItemServiceImpl implements TravelItemService {

    @Autowired
    private TravelItemDao travelItemDao;



    @Override
    public void addTravelItem(TravelItem travelItem) {

        travelItemDao.addTravelItem(travelItem);
    }

    @Override
    public PageResult selectTravelItemList(QueryPageBean queryPageBean) {

        Integer currentPage = queryPageBean.getCurrentPage() == null ? 1 : queryPageBean.getCurrentPage();

        Integer pageSize = queryPageBean.getPageSize() == null ? 10 : queryPageBean.getPageSize();

        PageHelper.startPage(currentPage,pageSize);
        
        String queryString = queryPageBean.getQueryString();

        TravelItem travelItem= JSON.parseObject(queryString,TravelItem.class);

        List<TravelItem> travelItems = travelItemDao.selectTravelItemList(travelItem);

        PageInfo<TravelItem> pageInfo = new PageInfo<>(travelItems);

        return new PageResult(pageInfo.getTotal(),pageInfo.getList());
    }

    @Override
    public void deleteTravelItemById(Integer id) {
        travelItemDao.deleteTravelItemById(id);
    }

    @Override
    public TravelItem selectById(Integer id) {
        return travelItemDao.selectById(id);
    }

    @Override
    public void editTravelItem(TravelItem travelItem) {
        travelItemDao.editTravelItem(travelItem);
    }

    @Override
    public List<TravelItem> selectTravelItemList() {
        return travelItemDao.selectAllTravelItemList();
    }

    @Override
    public List<Integer> selectTravelItemByGroupId(Integer id) {
        return travelItemDao.selectTravelItemByGroupId(id);
    }
}
